|
|
|
|
|
|
|
Figure 16.1
Light hitting a matte surface. |
|
|
|
|
|
|
|
|
If |A| and |B| are the lengths of the vectors, recall also that: |
|
|
|
 |
|
|
|
|
A B = |A| * |B| * Cos (q) |
|
|
|
|
|
|
|
|
where q is the angle between the vectors. |
|
|
|
|
|
|
|
|
You can normalize a vector by dividing its X, Y, and Z components by the vector's length. This produces a vector of length 1 pointing in the same direction as the original vector. Because normalized vectors have length one, they are often called unit vectors. |
|
|
|
|
|
|
|
|
If the vectors A and B are unit vectors, the dot product becomes simply: |
|
|
|
 |
|
|
|
|
A B = Cos (q) |
|
|
|
|
|
|
|
|
Now return to Lambert's law. If you normalize the vector L from the surface to the light source and the surface normal N, you can rewrite Lambert's law using vectors. |
|
|
|
 |
|
|
|
|
Id = Ii * kd * (L . N) |
|
|
|
|
|
|
|
|
You should calculate the intensities of the surface's red, green, and blue color components separately and then combine them using Visual Basic's RGB function. Break both the incident light and the surface's color coefficients into red, green, and blue values. This gives you three equations: |
|
|
|
 |
|
|
|
|
Id,red = II,red * kd,red * (L . N)
Id,green = II,green * kd,green * (L . N)
Id,blue = II,blue * kd,blue * (L . N) |
|
|
|
|
|
|
|
|
Notice that the value L N is the same in all three equations so you only need to calculate it once. |
|
|
|
|
|
|
|
|
The components of the incident light and the surface's reflection coefficients determine the general colors of the light and the surface. For example, a blue-green light source might give incident light values of Ii,red = 0, Ii,green = 255, and Ii,blue = 255. If the surface is yellow, its diffuse reflection coefficients might be kd,red = 1.0, kd,green = 1.0, and kd,blue = 0.0. |
|
|
|
|
|
|
|
|
If you assume that the light source is far away from the polygons you are drawing, the vector L from a polygon to the light source is approximately the same for every point in |
|
|
|
|
|